﻿'  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
'  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
'  PURPOSE.
'
'  Author:  Mojo/All YMSG 16 decryption credit goes to Martin Johnson of www.ExplicitStudios.com 
'  in essence this is a vb.net version  of his vb6 release... 



Option Explicit On

Module modYMSG
    Public Const AE As String = "À€"

    Public Function Assemble(ByVal Length As Integer) As String
        Assemble = "YMSG" + Chr(&H0) + Chr(16) + _
        New String(Chr(&H0), 2) + Chr(Length \ 256) + _
        Chr(Length Mod 256) & Chr(&H0)
    End Function

    Public Function GetChallenge(ByVal Username As String) As String
        GetChallenge = Assemble(Username.Length + 5) + Chr(&H57) + _
        New String(Chr(&H0), 8) + _
        "1" + AE + Username + AE
    End Function

    Public Function Login(ByVal Username As String, _
                          ByVal Seed As String, ByVal Y As String, _
                          ByVal T As String, ByVal Crumb As String, _
                          ByVal Invisible As Boolean)

        Dim Hash As String = YahooAuthHash(Crumb, Seed)
        Dim Packet As String = "1" + AE + Username + AE + "0" + AE + Username + AE + "277" + AE + Y + AE + "278" + AE + _
        T + AE + "307" + AE + Hash + AE + "244" + AE + "4194239" + AE + "2" + AE + Username + _
        AE + "2" + AE + "1" + AE + "98" + AE + "us" + AE + "135" + AE + "9.0.0.1389" + AE

        Login = Assemble(Packet.Length) + Chr(&H54) + _
        IIf(Invisible, New String(Chr(&H0), 3) + Chr(&HC), Chr(&H5A) + _
        Chr(&H55) + Chr(&HAA) + Chr(&H55)) + _
        New String(Chr(&H0), 4) + Packet

    End Function

End Module
